import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import store from '../store/index'

Vue.use(VueRouter)
import filmRouter from '@/router/routers/film'
import center from '@/router/routers/center'
import cinema from '@/router/routers/cinema'
import detail from '@/router/routers/detail';
import cityRouter from './routers/city'
// import { from } from 'core-js/fn/array'
// import city from './routers/city'



const routes = [{
        path: '/',
        redirect: '/film'
    },
    {
        path: '/vuex',
        component: () =>
            import ('@/views/vuex/vuex')

    },
    {
        path: '/dl',
        name: '/dl',
        component: () =>
            import ('@/views/login/dl')

    },
    {
        path: '/zc',
        name: '/zc',
        component: () =>
            import ('@/views/login/zc')
    },
    filmRouter,
    cinema,
    center,
    detail,
    // city,
    cityRouter,

]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})

//全局路由守卫
router.beforeEach((to, from, next) => {
    //不让进入的页面 写入数组 然后用逻辑去处理
    let arr = ['/center']
        //includes--下面这句意思是如果我即将要跳转的下一个页面 arr里有
    if (arr.includes(to.path)) {
        //store.state.token相当于你是认证过得用户
        if (store.state.token) {
            //直接放行
            next()

        } else {
            //如果不是跳转登录
            next({ path: '/dl' })
        }
    } else {
        next()
    }
})

export default router